package com.stoken.service.impl;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stoken.dao.MemberExtractListDao;
import com.stoken.dao.MemberWalletDao;
import com.stoken.domain.MemberBaseInfo;
import com.stoken.domain.MemberExtractList;
import com.stoken.domain.MemberWallet;
import com.stoken.service.MemberExtractListService;
import com.stoken.web.control.vo.Message;
import com.symbio.commons.Page;
import com.symbio.dao.hibernate.GenericDaoImpl;
import com.symbio.service.impl.AbstractServiceImpl;

@Service
public class MemberExtractListServiceImpl extends AbstractServiceImpl<MemberExtractList,Long> implements MemberExtractListService {
     
	@Autowired
	private MemberExtractListDao mExtListDao;
	
	@Autowired
	private MemberWalletDao memberWalletDao;
	
	


	@Override
	public GenericDaoImpl<MemberExtractList, Long> getDao() {		
		return mExtListDao;
	}

	@Override
	public Page<MemberExtractList> find(Page<MemberExtractList> pageData) {
		
		return mExtListDao.find(pageData);
	}

	@Override
	public Message processExtract(Long id, int extractState) {	
		
		MemberExtractList memberExtractList = mExtListDao.get(id);
		if(extractState == 2){ //表示提现处理失败
			//查询用户钱包信息
			MemberBaseInfo memberBaseInfo = memberExtractList.getBaseUsername();
			MemberWallet memberWallet = memberWalletDao.getMemberWalletByUserName(memberBaseInfo.getBaseUsername());
			memberWallet.setWalletRemain(memberWallet.getWalletRemain()+memberExtractList.getExtractAmount());
			memberWalletDao.update(memberWallet);
		}
	
		memberExtractList.setExtractTime(new Date());		
		memberExtractList.setExtractState(extractState);
		mExtListDao.update(memberExtractList);
		return new Message(0, "处理成功");
	}
	
	
}
